package com.zhongke.cotrun.controller;

import io.swagger.annotations.*;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;
import com.zhongke.cotrun.service.RegionService;
import com.zhongke.cotrun.model.pojo.Region;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import com.google.common.base.Preconditions;
import org.springframework.http.MediaType;

import com.zhongke.cotrun.common.util.APIResponse;

import java.util.List;

/**
 * 作者 yhl
 * 日期 2020-01-05 03:06:00
 * 描述 Region 服务
 */
@RestController
@RequestMapping("/region")
@CrossOrigin
@Api(tags = "区域信息服务")
public class RegionController extends AbstractController {

    private final Logger logger = LoggerFactory.getLogger(RegionController.class);

    @Resource
    public RegionService regionService;

    // http://localhost:8088/region/queryAllProvinces.json
    @ApiOperation(value = "查询所有省份", notes = "查询所有省份", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/queryAllProvinces.json")
    @ResponseBody
    public APIResponse<List<Region>> queryAllProvinces() {

        return APIResponse.returnSuccess(regionService.listAllChildrenRegion(414));
    }

    // http://localhost:8088/region/queryCityByProvinceId.json?provinceId=418
    @ApiOperation(value = "根据省id查询所有城市", notes = "根据省id查询所有城市", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/queryCityByProvinceId.json")
    @ResponseBody
    public APIResponse<List<Region>> queryCityByProvinceId(@ApiParam(value = "省份id", required = true) Integer provinceId) {

        return APIResponse.returnSuccess(regionService.listAllChildrenRegion(provinceId));
    }

    // http://localhost:8088/region/queryAreaByCityId.json?cityId=218
    @ApiOperation(value = "根据城市id查询所有区域", notes = "根据城市id查询所有区域", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/queryAreaByCityId.json")
    @ResponseBody
    public APIResponse<List<Region>> queryAreaByCityId(@ApiParam(value = "城市id", required = true) Integer cityId) {

        return APIResponse.returnSuccess(regionService.listAllChildrenRegion(cityId));
    }

   /* @ApiOperation(value = "根据id查询区域信息", notes = "根据id查询", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @RequestMapping(value = "/queryById.json")
   @ResponseBody
    public APIResponse<Region> queryById(@ApiParam(value = "对象id", required = true) Integer id) {
        Preconditions.checkNotNull(id);
        Preconditions.checkArgument(id > 0, "id(%s)必须大于0！", id);

        return APIResponse.returnSuccess(regionService.selectByPrimaryKey(id));
    }*/
}
